package com.htgd.gardenexpo.controller;


import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConCompetitionPrize;
import com.htgd.gardenexpo.page.PrizeQuery;
import com.htgd.gardenexpo.service.IGeConCompetitionPrizeService;
import com.htgd.gardenexpo.vo.GeConCompetitionPrizeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 赛事奖品 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-26
 */
@RestController
@RequestMapping("/api/competitionPrize")
@Api(tags = "赛事奖品")
@Slf4j
public class GeConCompetitionPrizeController {
    @Autowired
    private IGeConCompetitionPrizeService geConCompetitionPrizeService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConCompetitionPrize geConCompetitionPrize) {
        log.info("赛事奖品-添加:{}",geConCompetitionPrize);
        return geConCompetitionPrizeService.add(geConCompetitionPrize);
    }

    @PostMapping(value = "/edit")
    @ApiOperation("编辑")
    public CommonResult edit(@RequestBody GeConCompetitionPrize geConCompetitionPrize) {
        log.info("赛事奖品-编辑:{}",geConCompetitionPrize);
        return geConCompetitionPrizeService.edit(geConCompetitionPrize);
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult delete(String id) {
        geConCompetitionPrizeService.removeById(id);
        return CommonResult.success("删除成功");
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询")
    public CommonResult<List<GeConCompetitionPrizeVO>> list(PrizeQuery prizeQuery) {
        PageInfo<GeConCompetitionPrizeVO> list = geConCompetitionPrizeService.pageList(prizeQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

}
